{% extends "../main.html" %}

{% block title %}{{ _("Black Market") }}{% end %}

{% block header %}
<script src="/static/js/pages/market/view.js"></script>
{% from tornado.options import options %}
{% end %}

{% block modals %}
    <!-- Hidden Download Form -->
    <div id="buy-market-item-modal" class="modal hide fade" style="display: none;">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h3>
                {{ _("Details") }}
            </h3>
        </div>
        <div class="modal-body">
            <h4 id="name"></h4>
            <hr>
            <div class="row">
                <div class="span4">
                    <img id="image" class="img-polaroid" src=""></img>
                </div>
                <div class="span2">
                    <p>
                        <i class="icon-bookmark"></i>
                        {% if options.banking %}{{ _("Price") }}: {{ _("$") }}{% else %}{{ _("Cost") }}:{% end %} <span id="price"></span>
                    </p>
                    <p>
                        <i class="icon-book"></i>
                        {{ _("Description") }}:
                    </p>
                    <blockquote>
                        <small id="description"></small>
                    </blockquote>
                </div>
            </div>
        </div>
        <form id="buy-market-item-form" method="post" action="/user/market">
            {% raw xsrf_form_html() %}
            <input id="buy-market-item-uuid" type="hidden" id="uuid" name="uuid" />
        </form>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">{{ _("Close") }}</a>
            <button id="buy-market-item-submit" type="button" class="btn btn-primary">
                {{ _("Buy Upgrade") }}
            </button>
        </div>
    </div>
{% end %}

{% block content %}
{% from models.MarketItem import MarketItem %}
<div class="container">
    <h2>
        <i class="fa fa-shopping-cart"></i>
        {{ _("Black Market") }}
    </h2>
    <br />
    {% if errors is not None and len(errors) != 0 %}
        {% for error in errors %}
        <div class="alert alert-error">
            <a class="close" data-dismiss="alert" href="#">&times;</a>
            <h4 class="alert-heading">{{ _("ERROR") }}</h4>
            {{ error }}
        </div>
        {% end %}
    {% end %}
    <div class="well">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>#</th>
                    <th>{{ _("Name") }}</th>
                    <th>{% if options.banking %}{{ _("Price") }}{% else %}{{ _("Cost") }}{% end %}</th>
                    <th>
                        <!-- Button -->
                    </th>
                </tr>
            </thead>
            <tbody>
                {% for index, item in enumerate(MarketItem.all()) %}
                <tr>
                    <td>{{ index + 1 }}</td>
                    <td>{{ item.name }}</td>
                    <td>{% if options.banking %}{{ _("$") }}{% end %}{{ item.price }}</td>
                    <td>
                        {% if not user.has_item(item.name) %}
                        <a id="item-details-button{{ index }}" class="btn btn-mini" data-toggle="modal" href="#buy-market-item-modal" data-uuid="{{ item.uuid }}">
                            {{ _("Details") }}
                        </a>
                        {% else %}
                        <i>{{ _("Purchased") }}</i>
                        {% end %}
                    </td>
                </tr>
                {% end %}
            </tbody>
        </table>
    </div>
</div>
{% end %}
